package kr.co.redcircle.service.oAuth.model;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.xpath.XPath;

public class SNSAuthInformation {
	
	private String application_id;
	private String secret_id;
	private String callback_uri;
	private String scope;

	public SNSAuthInformation(Element moduleElement) {
		
		try {
			
			Element authInfoElement = (Element)XPath.selectSingleNode(moduleElement, "//module[@id='"+moduleElement.getAttributeValue("id")+"']/collection[@id='keys']");
			
			List<Element> keyList = authInfoElement.getChildren();
			
			for (Element targetElement : keyList){
				
				String keyID = targetElement.getAttributeValue("type");
				String keyVALUE = targetElement.getValue();
				
				if (keyID != null){
					if(keyID.equals("application_id")){
						this.setApplication_id(keyVALUE);
					}else if(keyID.equals("secret_id")){
						this.setSecret_id(keyVALUE);
					}else if(keyID.equals("callback_uri")){
						this.setCallback_uri(keyVALUE);
					}else if(keyID.equals("scope")){
						this.setScope(keyVALUE);
					}
				}
				
			}
			
			
		} catch (JDOMException e) {
			e.printStackTrace();
		}
		
	}

	public String getApplication_id() {
		return application_id;
	}

	public void setApplication_id(String application_id) {
		this.application_id = application_id;
	}

	public String getSecret_id() {
		return secret_id;
	}

	public void setSecret_id(String secret_id) {
		this.secret_id = secret_id;
	}

	public String getCallback_uri() {
		return callback_uri;
	}

	public void setCallback_uri(String callback_uri) {
		this.callback_uri = callback_uri;
	}

	@Override
	public String toString() {
		return "SNSAuthInformation [application_id=" + application_id
				+ ", secret_id=" + secret_id + ", callback_uri=" + callback_uri
				+ ", scope=" + scope + "]";
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}
}
